package com.scyshkj.university.wechat.wanxiao;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.scyshkj.university.wechat.pay.WechatUnifiedOrderRequestParameter;
import com.scyshkj.university.wechat.utils.DateUtils;
import com.scyshkj.university.wechat.utils.ParameterToMap;
import com.scyshkj.university.wechat.utils.RandomStringUtil;
import lombok.Data;

import java.math.BigDecimal;

/**
 * Created by 唐旭 on 2016/11/24.
 */
@Data
public class WanxiaoRechargeRequest implements ParameterToMap {
    @JsonProperty("access_token")
    private String accessToken;

    @JsonProperty("app_id")
    private int appId;

    @JsonProperty("pay_code")
    private String payCode;

    @JsonProperty("recharge_order_no")
    private String rechargeOrderNo;

    @JsonProperty("apply_id")
    private String applyId;

    @JsonProperty("out_id")
    private String outId;

    @JsonProperty("recharge_amount")
    private BigDecimal rechargeAmount;

    @JsonProperty("pay_time")
    private String payTime = DateUtils.toDateText(DateUtils.now(), "yyyyMMddhhmmss");

    @JsonProperty("norce_str")
    private String norceStr = RandomStringUtil.getRandomString(32);

    public WanxiaoRechargeRequest() {
    }

    public WanxiaoRechargeRequest(WechatUnifiedOrderRequestParameter outTradeNo, PayApplyResult applyResult, WanxiaoProperties wanxiaoProperties) {
        this.accessToken = outTradeNo.getAccessToken();
        this.appId = wanxiaoProperties.getAppId();
        this.payCode = wanxiaoProperties.getPayCode();
        this.rechargeOrderNo = outTradeNo.getUuid();
        this.appId = Integer.valueOf(outTradeNo.getAppid());
        this.outId = applyResult.getOutId();
        this.rechargeAmount = new BigDecimal(outTradeNo.getTotal_fee());
    }
}
